package com.ourteam.system.api;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

import com.ourteam.frame.web.AbstractSearchModel;
import com.ourteam.system.dao.SysUserDAOQueryBean;
import com.ourteam.system.domain.SystemUser;

public class SystemAccountSearchModel extends AbstractSearchModel<SysUserDAOQueryBean> {

	private String name;

	private String account;

	private String userDepartment;

	private String userDepartmentRole;

	private String userMobilePhone;

	private String userOfficePhone;

	private String userRole;

	private String[] status;
	
	private String userStatus;
	
	private String code;

	private long[] excludeIds;

	public long[] getExcludeIds() {
		return excludeIds;
	}

	public void setExcludeIds(long[] excludeIds) {
		this.excludeIds = excludeIds;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getUserDepartment() {
		return userDepartment;
	}

	public void setUserDepartment(String userDepartment) {
		this.userDepartment = userDepartment;
	}

	public String getUserDepartmentRole() {
		return userDepartmentRole;
	}

	public void setUserDepartmentRole(String userDepartmentRole) {
		this.userDepartmentRole = userDepartmentRole;
	}

	public String getUserMobilePhone() {
		return userMobilePhone;
	}

	public void setUserMobilePhone(String userMobilePhone) {
		this.userMobilePhone = userMobilePhone;
	}

	public String getUserOfficePhone() {
		return userOfficePhone;
	}

	public void setUserOfficePhone(String userOfficePhone) {
		this.userOfficePhone = userOfficePhone;
	}

	public String getUserRole() {
		return userRole;
	}

	public void setUserRole(String userRole) {
		this.userRole = userRole;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	public String getUserStatus() {
		return userStatus;
	}

	public void setUserStatus(String userStatus) {
		this.userStatus = userStatus;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return SystemUser.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(SysUserDAOQueryBean queryBean) throws Exception {

		SysUserDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		criteria.andUserTypeNotEqualToOrIsNull("admin");

		if (StringUtils.isNotEmpty(account)) {
			criteria.andUserAccountLike(account);
		}

		if (StringUtils.isNotEmpty(name)) {
			criteria.andUserNameLike(name);
		}

		if (StringUtils.isNotEmpty(userDepartment)) {
			criteria.andUserDepartmentLike(userDepartment);
		}

		if (StringUtils.isNotEmpty(this.userDepartmentRole)) {
			criteria.andUserDepartmentRoleLike(userDepartmentRole);
		}

		if (StringUtils.isNotEmpty(this.userMobilePhone)) {
			criteria.andUserMobilePhoneLike(userMobilePhone);
		}

		if (StringUtils.isNotEmpty(this.userOfficePhone)) {
			criteria.andUserOfficePhoneLike(userOfficePhone);
		}

		if (StringUtils.isNotEmpty(this.userRole)) {
			criteria.andUserRoleLike(userRole);
		}
		
		if (ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(status);
		}
		
		if (StringUtils.isNotEmpty(this.userStatus)) {
			criteria.andUserStatusEqualTo(userStatus);
		}
		
		if (StringUtils.isNotEmpty(this.code)) {
			criteria.andUserCodeEqualTo(code);
		}

		if (ArrayUtils.isNotEmpty(this.excludeIds)) {
			criteria.andIdNotIn(excludeIds);
		}

	}

}
